package com.newly.common.base.entity.auth;

import com.newly.common.base.constants.AuthConstant;
import com.newly.common.base.entity.sys.auth.entity.po.AuthEntityPo;
import com.newly.common.base.entity.sys.auth.role.po.RolePo;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.Map;


/**
 * @program: newly-parent
 * @remark:
 * @author: guan
 * @create: 2021-12-23 05:17
 */
@Data
public class AuthPayload implements Serializable {
    private static final long serialVersionUID = -1;
    /**
     * 角色id
     */
    private int roleId;

    /**
     * 角色名称
     */
    private String roleName;

    /**
     * 创建用户
     */
    private Long createBy;

    /**
     * 父角色id
     */
    private int parentId;

    /**
     * 授权标识
     */
    private String auth;

    /**
     * 当前用户角色
     */
    private boolean currentFlag;

    /**
     * 类型
     */
    private int type;

    /**
     * 权限实体
     */
    private Map<AuthConstant.AuthEntityType, List<AuthEntity>> authEntities;

    public AuthPayload() {
    }

    public AuthPayload(int type) {
        this.type = type;
    }

    public AuthPayload(RolePo rolePo) {
        this.roleId = rolePo.getId();
        this.roleName = rolePo.getName();
        this.parentId = rolePo.getParentId();
        this.type = rolePo.getType();
        this.currentFlag = rolePo.isCurrentFlag();
        this.createBy = rolePo.getCreateBy();
        this.auth = rolePo.getAuth();
    }

    /**
     * 权限实体
     */
    @Data
    public static class AuthEntity implements Serializable {
        private static final long serialVersionUID = -1;

        /**
         * 实体id，例如：菜单id或设备id
         */
        private String entityId;

        /**
         * 实体类型，例如：菜单类型或设备类型
         */
        private int type;

        /**
         * 备注
         */
        private String remark;

        public AuthEntity(AuthEntityPo authEntityPo) {
            this.entityId = authEntityPo.getEntityId();
            this.type = authEntityPo.getType();
            this.remark = authEntityPo.getRemark();
        }

        public AuthEntity() {
        }

        public AuthEntity(String entityId, int type, String remark) {
            this.entityId = entityId;
            this.type = type;
            this.remark = remark;
        }
    }
}
